<template>
	<view class="news">
		<view class="clinics" v-for="(item,index) in list" :key="list.item" @click="jumpChat(index)">
			<view class="images">
				<image :src="item.userProfile.avatar" mode="scaleToFill" style="width: 100rpx; height: 100rpx;"></image>
			</view>
			<view class="nickLastTime">
				<view class="nick">
					<text>{{item.userProfile.nick}}</text>
					<text>{{item.lastMessage.lastTime | formdate("yyyy-MM-dd")}}</text>
				</view>
				<view class="lastTime">
					<text>{{item.lastMessage.messageForShow}}</text>
					<!-- <text><text>{{item.number}}</text></text> -->
				</view>
			</view>
		</view>

		<view class="bottomTab">
			<view class="msg1">
				<image src="../../../../static/image/doctor/info1.png" mode="scaleToFill" style="width: 40rpx; height: 40rpx;"></image>
				<text>消息</text>
			</view>
			<view class="my1" @click="jumpMy">
				<image src="../../../../static/image/doctor/my.png" mode="scaleToFill" style="width: 40rpx; height: 40rpx;"></image>
				<text>我的</text>
			</view>
		</view>
	</view>
</template>

<script>
	import TIM from 'tim-wx-sdk';
	export default {
		onLoad() {},
		onShow() {
			uni.hideHomeButton();
			// 获取消息列表
			this.getMsgList();
			// 获取未读信息
			// this.getUnreadMsg("C2CoelgY0UV2CiQG7LAJbVcPGqku928");
		},
		data() {
			return {
				list: null,
				userIDList: [],
			};
		},
		methods: {
			// 拉取会话列表
			getMsgList() {
				console.log(`拉取会话列表拉取会话列表拉取会话列表拉取会话列表`)
				let self = this;
				this.globalData.tim.getConversationList().then(res => {
					self.list = res.data.conversationList;
				}).catch(err => {
					console.warn(err);
				});
			},

			jumpChat(index) {
				let doctInfo = this.list.filter((value, key, arr) => {
					if (index == key) {
						return value;
					};
				});
				uni.navigateTo({
					url: `../chat/chat?openid=${doctInfo[0].userProfile.userID}`
				})
			},
			// 将某会话下所有未读消息已读上报
			getUnreadMsg(id) {
				this.globalData.tim.setMessageRead({
					conversationID: id
				}).then(res => {
					console.log(res);
				}).catch(err => {
					console.warn('setMessageRead error:', err);
				});
			},

			jumpMy() {
				uni.redirectTo({
					url: "../profile1/profile1"
				});
			},
		},
		"filters": {
			formdate(value) {
				let date = new Date(value * 1000);
				let h = date.getHours() + ':';
				let m = date.getMinutes();
				return h + m;
			}
		},
	}
</script>

<style lang="scss">
	.news {
		width: 750rpx;
		height: 100vh;
		background-color: #F5F8FA;
		overflow: hidden;
	}

	.clinics {
		display: flex;
		width: 690rpx;
		height: 140rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		margin: 20rpx auto 0rpx;
		padding: 20rpx;
	}

	.images {
		margin-right: 25rpx;

		image {
			border-radius: 50%;
		}
	}

	.nickLastTime {
		width: 100%;
		display: flex;
		flex-wrap: wrap;
	}

	.nick,
	.lastTime {
		@include chuizhilianduan;
		width: 100%;
	}

	.nick {
		>text {
			font-family: PingFang SC;

			&:first-of-type {
				font-size: 32rpx;
				font-weight: 400;
				color: rgba(40, 40, 40, 1);
			}

			&:last-of-type {
				font-size: 22rpx;
				color: rgba(138, 138, 153, 1);
			}
		}
	}

	.lastTime {
		>text {
			&:first-of-type {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: rgba(138, 138, 153, 1);
			}
		}
	}

	.bottomTab {
		width: 750rpx;
		height: 100rpx;
		background-color: #FFFFFF;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		display: flex;

		>view {
			flex: 1;
			height: 100%;
			display: flex;
			flex-wrap: wrap;
			justify-content: center;
			align-items: center;

			>text {
				width: 100%;
				text-align: center;
			}

			>image {
				transform: translateY(25%);
			}
		}
	}

	.my1 {
		>text {
			color: #bababa;
		}
	}

	.msg1 {
		>text {
			color: #2DD1BC;
		}
	}
</style>
